<template>
  <div class="wrap">
    <div class="show-title">
      <span>视频日志</span>
    </div>
    <!-- 查询 -->
    <el-form
      :inline="true"
      :model="ruleform"
      ref="from"
      :rules="rules"
      class="demo-form-inline form-wrap"
    >
      <el-form-item label="票据" prop="ticket">
        <el-input
          v-model="ruleform.ticket"
          message
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="设备别名" prop="alias">
        <el-input
          v-model="ruleform.alias"
          message
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="开始时间" prop="start_time">
        <el-date-picker
          time-arrow-control
          v-model="ruleform.start_time"
          type="datetime"
          placeholder="开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="end_time">
        <el-date-picker
          time-arrow-control
          v-model="ruleform.end_time"
          type="datetime"
          placeholder="结束时间"
        >
        </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="视频协议" prop="ptl">
        <el-input
          v-model="ruleform.ptl"
          message
          placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="流媒体主机" prop="host_sn">
        <el-input
          v-model="ruleform.host_sn"
          message
          placeholder="请输入"
        ></el-input>
      </el-form-item> -->
      <el-form-item label="协议" prop="ptl">
        <el-select
          v-model="ruleform.ptl"
          placeholder="请选择"
          ref="prevSelect"
          @input="fnClickPrev"
          :multiple="true"
          :multiple-limit="1"
        >
          <el-option label="RTSP" value="RTSP"></el-option>
          <el-option label="RTMP" value="RTMP"></el-option>
          <el-option label="HTTP-FLV" value="HTTP-FLV"></el-option>
          <el-option label="WS-FLV" value="WS-FLV"></el-option>
          <!-- <el-option label="HLS" value="HLS"></el-option> -->
          <el-option label="CMS" value="CMS"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="主机" prop="host_sn">
        <el-select
          v-model="ruleform.host_sn"
          placeholder="请选择"
          ref="nextSelect"
          @input="fnClickNext"
          :multiple="true"
          :multiple-limit="1"
        >
          <el-option
            v-for="item in hosts_arr"
            :key="item"
            :label="item"
            :value="item"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" plain @click="onSubmit('from')"
          >查询</el-button
        >
        <!-- <el-button
          type="success"
          plain
          @click="onExport2excel('from')"
          >导出日志</el-button
        > -->
        <el-button type="warning" plain @click="onReset('from')"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table
      class="form-table"
      ref="table"
      :data="tableData"
      border
      style="width: 100%"
      stripe
      @selection-change="handleSelectionChange"
      @sort-change="changeSort"
      :row-key="getRowKeys"
    >
      <el-table-column
        type="selection"
        width="40"
        align="center"
        :reserve-selection="true"
        :key="1"
        fixed
      ></el-table-column>
      <el-table-column
        prop="ticket"
        label="票据"
        min-width="160"
        align="center"
      >
        <template slot-scope="scope">{{
          scope.row.ticket
        }}</template>
      </el-table-column>
      <el-table-column
        prop="sn"
        label="设备序列号"
        min-width="160"
        align="center"
      >
        <template slot-scope="scope">{{ scope.row.sn }}</template>
      </el-table-column>
      <el-table-column
        prop="alias"
        label="设备别名"
        min-width="120"
        align="center"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{ scope.row.alias }}
        </template>
      </el-table-column>

      <el-table-column
        prop="channel"
        label="通道号"
        min-width="40"
        align="center"
      >
        <template slot-scope="scope">{{
          scope.row.channel
        }}</template>
      </el-table-column>

      <el-table-column
        prop="remote_ip"
        label="来源ip"
        min-width="100"
        align="center"
      >
        <template slot-scope="scope">{{
          scope.row.remote_ip
        }}</template>
      </el-table-column>

      <el-table-column
        prop="created_time"
        label="播放时间"
        min-width="120"
        align="center"
        sortable="custom"
      >
        <template slot-scope="scope">{{
          scope.row.created_time
        }}</template>
      </el-table-column>
      <el-table-column
        prop="ptl"
        label="视频协议"
        min-width="60"
        align="center"
      >
        <template slot-scope="scope">{{ scope.row.ptl }}</template>
      </el-table-column>
      <el-table-column
        prop="host_sn"
        label="流媒体主机"
        min-width="100"
        align="center"
      >
        <template slot-scope="scope">{{
          scope.row.host_sn
        }}</template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      right
      background
      layout="total,prev, pager, next, sizes,jumper"
      :page-sizes="pageSizesArr"
      :page-size="pagesize"
      :total="total"
      :current-page="currpage"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination>
  </div>
</template>

<script>
import { getData, postData } from "@/request/http";
export default {
  name: "palylogs",
  props: {},
  data() {
    return {
      total: 0, // 总数
      currpage: 1, //当前页
      pagesize: globalPageSizes[0], //初始显示，一页几个
      pageSizesArr: globalPageSizes, //globalPageSizes在public--config中全局配置，每页显示个数数组      total: 0, // 总数
      tableData: [], // 表格数据
      tableChecked: [], // 多选
      batchDelectId: [], //批量删除id
      checkAll: false, // 是否全选状态
      ruleform: {
        ticket: "",
        alias: "",
        start_time: "",
        end_time: "",
        ptl: "",
        host_sn: "",
      },
      rules: {
        ticket: [{ required: false, message: "请输入票据", trigger: "blur" }],
        alias: [
          { required: false, message: "请输入设备别名", trigger: "blur" },
        ],
        start_time: [
          { required: false, message: "请输入开始时间", trigger: "blur" },
        ],
        end_time: [
          { required: false, message: "请输入结束时间", trigger: "blur" },
        ],
        ptl: [{ required: false, message: "请选择协议", trigger: "blur" }],
        host_sn: [{ required: false, message: "请选择主机", trigger: "blur" }],
      },
      hosts_arr: [],
      time_order: "DESC", //默认倒序
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.search();
    this.initHostSelect();
  },
  methods: {
    //查询
    onSubmit(formName) {
      this.currpage = 1;
      this.search();
    },
    //初始列表
    search() {
      let ticket_sub = this.ruleform.ticket;
      let alias_sub = this.ruleform.alias;
      let start_time_sub = this.ruleform.start_time;
      let end_time_sub = this.ruleform.end_time;
      let ptl_sub = this.ruleform.ptl[0];
      let host_sn_sub = this.ruleform.host_sn[0];
      let dataParams = {
        ticket: ticket_sub ? ticket_sub : "",
        alias: alias_sub ? alias_sub : "",
        start_time: start_time_sub ? start_time_sub.getTime() : "",
        end_time: end_time_sub ? end_time_sub.getTime() : "",
        ptl: ptl_sub ? ptl_sub : "",
        host_sn: host_sn_sub ? host_sn_sub : "",
        page: this.currpage,
        page_num: this.pagesize,
        time_order: this.time_order,
      };
      postData("/adminweb/ydts-ticket/ticket/checked/log/list", dataParams)
        .then((res) => {
          // console.log(res);
          if (res.code == 0) {
            if (!res.datas || !res.datas.logs) {
              return;
            }
            let logs = res.datas.logs;
            this.tableData = logs;
            //  console.log(logs);
            this.total = res.datas.total_count;
          } else if (res.code == -56055) {
            return;
          } else {
            this.$message.error(res.code + "，" + res.msg);
          }
        })
        .catch((res) => {
          this.$message.error(res.code + "，" + res.msg);
        });
    },
    //获取主机列表下拉框,
    initHostSelect() {
      postData("/adminweb/host/list", {
        host_type: 2,
      })
        .then((res) => {
          // console.log(res);
          if (res.code == 0) {
            let hosts = res.datas.hosts;
            var hosts_arr = [];
            for (var i = 0; i < hosts.length; i++) {
              hosts_arr.push(hosts[i].sn);
            }
            this.hosts_arr = hosts_arr;
          } else if (res.code == -56055) {
            return;
          } else {
            this.$message.error(res.code + "，" + res.msg);
          }
        })
        .catch((res) => {
          //this.$message.error(res.code + "，" + res.msg);
        });
    },

    //导出查询日志
    /* onExport2excel() {
      let ticket_sub = this.ruleform.ticket;
      let alias_sub = this.ruleform.alias;
      let start_time_sub = this.ruleform.start_time;
      let end_time_sub = this.ruleform.end_time;
      let dataParams = {
        ticket: ticket_sub ? ticket_sub : "",
        alias: alias_sub ? alias_sub : "",
        start_time: start_time_sub ? start_time_sub.getTime() : "",
        end_time: end_time_sub ? end_time_sub.getTime() : "",
       
        logs: this.batchDelectId.length == 0 ? [] : this.batchDelectId,
        time_order: this.time_order,
      };
      postData("/adminweb/video/live/playing/log/export2excel", dataParams, {
        timeout: 120000,
      })
        .then((res) => {
          // console.log(res);
          if (res.code == 0) {
            let excel_uri = res.datas.excel_uri;
            let download_url = baseUrl + "/" + excel_uri;
            window.location.href = download_url;
          } else if (res.code == -58021) {
            this.$message.error("未找到设备的播放日志");
          } else if (res.code == -56055) {
            return;
          } else {
            this.$message.error(res.code + "，" + res.msg);
          }
        })
        .catch((res) => {
          this.$message.error(res.code + "，" + res.msg);
        });
    }, */

    // 获取row的key值
    getRowKeys(row) {
      return row.log_id;
    },
    //点击,第几页
    handleCurrentChange(cpage) {
      this.currpage = cpage;
      this.search();
    },
    //每页有几条
    handleSizeChange(psize) {
      this.currpage = 1;
      this.pagesize = psize;
      this.search();
    },
    //操作多选
    handleSelectionChange(val) {
      var that = this;
      this.batchDelectId = [];
      that.tableChecked = val;
      if (val.length > 0) {
        for (let i = 0; i < val.length; i++) {
          this.batchDelectId.push(val[i]["log_id"]);
        }
      }
    },
    //排序
    changeSort(data) {
      if (data.order == "descending") {
        this.time_order = "DESC";
      } else if (data.order == "ascending") {
        this.time_order = "ASC";
      }
      this.currpage = 1;
      this.search();
      // console.log(val);
    },
    //重置
    onReset() {
      this.currpage = 1;
      this.ruleform.ticket = "";
      this.ruleform.alias = "";
      this.ruleform.start_time = "";
      this.ruleform.end_time = "";
      this.ruleform.ptl = "";
      this.ruleform.host_sn = "";

      this.search();
      //清空table的checked
      this.$refs.table.clearSelection();
    },
    //select点击后收起,协议
    fnClickPrev() {
      !!this.$refs.prevSelect && this.$refs.prevSelect.handleClose();
    },
    //select点击后收起,流媒体主机
    fnClickNext() {
      !!this.$refs.nextSelect && this.$refs.nextSelect.handleClose();
    },
  },
};
</script>
<style scoped>
.form-wrap {
  padding-left: 20px;
}

/* 更改table,表头背景 */
.wrap >>> .el-table--border th,
.el-table__fixed-right-patch {
  /* background: #c0dee2; */
  background: #f0f3f4;
}
.wrap {
  background-color: #fff;
  padding: 15px;
  overflow: hidden;
}
.form-table {
  margin-top: 20px;
}
.wrap >>> .el-pagination {
  float: right;
  margin-top: 30px;
}

.batch-btn-con {
  background: #fff;
  margin-top: 70px;
}
.wrap >>> .tips {
  margin-top: 10px;
  display: block;
  font-size: 15px;
}

/*title*/
.show-title {
  width: 100%;
  height: 40px;
  line-height: 40px;
  position: relative;
  background: #c0dee2;
  padding-left: 15px;
  font-size: 14px;
  margin: 6px 0 20px 0;
  border-radius: 12px 12px 0 0;
  font-weight: bold;
}

.show-title::before {
  content: "";
  width: 2px;
  height: 16px;
  background: #676a6d;
  position: absolute;
  top: 12px;
  left: 27px;
}

.show-title span {
  float: left;
  color: #676a6d;
  margin-left: 25px;
}
/* title显示名称id */
.wrap >>> .table-wrap {
  border: none;
  box-shadow: none;
}
.wrap >>> .el-divider__text.is-center {
  font-size: 17px;
}
.wrap >>> .el-divider__text {
  background: #c0dee2;
  padding: 15px;
  border-radius: 8px;
}
.title-list {
  background: #fff;
  padding-left: 20px;
  height: 80px;
}
.title-list .txt {
  height: 10px;
}
</style>
